import unittest
from time import sleep
from common.databaseTool import DatabaseTool
from Page.address_page import *


class AddressFCase(unittest.TestCase):

    def setUp(self):
        self.driver = open_op_browser(path)
        self.ac = AddressPage(self.driver)
        self.ac.open_url(login_url)

    @classmethod
    def setUpClass(cls):
        cls.db = DatabaseTool("168168", "ecshop_db", port=3308)

    def tearDown(self):
        sql = "delete from ecs_user_address where user_id =113"
        self.db.execute_one(sql)
        self.ac.close()

    # @classmethod
    # def tearDownClass(cls):
    #     sql = "delete from ecs_user_address where user_id =113"
    #     cls.db.execute_one(sql)

    # 检测添加收货地址,不选择国家有弹框显示
    def test_address_f_case01(self):
        # 在页面内点击用户信息进入个人信息修改页面
        self.ac.click_address()
        # 定位选择国家
        self.ac.click_country("请选择国家")
        # # 定位选择省份
        # self.ac.click_province("四川省")
        # # 定位城市
        # sleep(5)
        # self.ac.click_city("成都市")
        # # 定位区域
        # sleep(5)
        # self.ac.click_district("青羊区")
        # 定位输入收货人
        self.ac.input_consignee("lisa")
        # 定位输入邮箱地址
        self.ac.input_addr_email("1234567@qq.com")
        # 定位 输入详细地址
        self.ac.input_address("天府新谷")
        # 定位邮政编码
        self.ac.input_zip_code("51112")
        # 定位电话
        self.ac.input_phone("8898433")
        # 定位手机号
        self.ac.input_tel('15182107333')
        # 定位新增收货地址按钮
        sleep(5)
        self.ac.add_address()
        al = self.driver.switch_to.alert
        sleep(5)
        try:
            self.assertIn("请您选择收货人所在国家！", al.text, msg="用例执行失败")
            al.accept()
        except Exception as e:
            raise ("用例执行失败")


if __name__ == '__main__':
    unittest.main()
